﻿<navigation:Page xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"  x:Class="PhotoManagerApp.Views.Profile" 
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                 mc:Ignorable="d"
                 xmlns:converter="clr-namespace:PhotoManagerApp.Helpers"
                 xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
                 d:DesignWidth="640" d:DesignHeight="480"
                 Title="Profile Page">
    
    <navigation:Page.Resources>
        <converter:ByteConverter x:Key="ByteConverter" />
    </navigation:Page.Resources>
    
    <Grid x:Name="LayoutRoot">
        
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0.5*"/>
            <ColumnDefinition Width="0.5*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="auto"/>
        </Grid.RowDefinitions>

        <sdk:DataGrid ItemsSource="{Binding Folders}" Grid.Row="0" 
                      AutoGenerateColumns="False" IsReadOnly="True"
                      SelectedItem="{Binding CurrentFolder, Mode=TwoWay}">
            <sdk:DataGrid.Columns>
                <sdk:DataGridTextColumn Header="Folder ID" Binding="{Binding FolderID}"/>
                <sdk:DataGridTextColumn Header="Folder name" Binding="{Binding FolderName}"/>
            </sdk:DataGrid.Columns>
        </sdk:DataGrid>
        
        <StackPanel Grid.Row="1">
            <Grid>
                <StackPanel>
                    <TextBlock Text="EditFolder" FontWeight="ExtraBold"/>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="ID: " Width="40"/>
                        <TextBlock Text="{Binding CurrentFolder.FolderID}"/>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="Name:" Width="40"/>
                        <TextBox Width="150" Text="{Binding CurrentFolder.FolderName, Mode=TwoWay, UpdateSourceTrigger=Default}" />
                        <Button Name="ButtonSave" Content="Save" Command="{Binding UpdateCommand}"/>
                        <Button Name="ButtonDelete" Content="Delete" Command="{Binding DeleteCommand}"/>
                    </StackPanel>
                    <TextBlock Text="InsertFolder" FontWeight="ExtraBold"/>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="Name:" Width="40"/>
                        <TextBox Width="150" Text="{Binding NewFolder.FolderName, Mode=TwoWay, UpdateSourceTrigger=Default}" />
                        <Button Name="ButtonAdd" Content="Add" Command="{Binding AddCommand}"/>
                    </StackPanel>
                </StackPanel>
            </Grid>
            <StackPanel>
                <TextBlock Text="EditImage" FontWeight="ExtraBold"/>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="ID: " Width="40"/>
                    <TextBlock Text="{Binding CurrentImage.imageID}"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="Name:" Width="40"/>
                    <TextBox Width="150" Text="{Binding CurrentImage.ImageName, Mode=TwoWay, UpdateSourceTrigger=Default}" />
                    <TextBlock Text="Description:" Width="70"/>
                    <TextBox Width="150" Text="{Binding CurrentImage.Description, Mode=TwoWay, UpdateSourceTrigger=Default}" />
                    <TextBlock Text="IsPublic"/>
                    <CheckBox IsChecked="{Binding CurrentImage.IsPublic, Mode=TwoWay}"/>
                    <Button Name="ButtonImageSave" Content="Save" Command="{Binding UpdateImageCommand}"/>
                    <Button Name="ButtonImageDelete" Content="Delete" Command="{Binding DeleteImageCommand}"/>
                </StackPanel>
                <Button HorizontalAlignment="Left" Content="Upload Photo" Click="ButtonUploadPhoto_Click" Width="120"/>
            </StackPanel>
        </StackPanel>

        <ListBox Grid.Column="1" Height="350" x:Name="ListBoxImages" 
                 SelectedItem="{Binding CurrentImage, Mode=TwoWay}"
                 ItemsSource="{Binding Images}" HorizontalAlignment="Stretch">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <Image Height="100" Width="100"
                               Source="{Binding ImageData, Mode=TwoWay, Converter={StaticResource ByteConverter}}"/>
                        <TextBlock Text="{Binding ImageName, Mode=TwoWay}"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

    </Grid>
</navigation:Page>
